package com.augurit.gzcgwsp.csshlj.convert;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;
import org.springframework.beans.factory.annotation.Autowired;

import com.augurit.gzcgwsp.csshlj.entity.CsshljczBa;
import com.augurit.gzcgwsp.csshlj.form.CsshljczBaForm;
import com.augurit.gzcgwsp.csshlj.service.ICsshljCzService;
import com.augurit.gzcgwsp.csshlj.web.form.CsshljCzForm;



public class CsshljczBaConvertor {
	@Autowired
	private ICsshljCzService csshljCzService;
	
    public static CsshljczBaForm convertVoToForm(CsshljczBa entity ,CsshljCzForm qsForm) {
        if (entity == null) return null;
        CsshljczBaForm form = new DozerBeanMapper().map(qsForm, CsshljczBaForm.class);
        form.setId(entity.getId());
        form.setAcceptNo(entity.getAcceptNo());
        form.setCzid(entity.getCzid());
        form.setSqrq(entity.getSqrq());
        return form;
    }
    
    
    public static void convertFormToVo(CsshljczBaForm form, CsshljczBa entity) {
        if (form == null) return;
        if (entity == null) entity = new CsshljczBa();
        
        new DozerBeanMapper().map(form, entity);
    }
    
    public List<CsshljczBaForm> convertVoListToFormList(List<CsshljczBa> csshljczBaList) {
        if(csshljczBaList != null && csshljczBaList.size() > 0) {
            List<CsshljczBaForm> csshljczBaFormList = new ArrayList();
            for(int i=0; i<csshljczBaList.size(); i++) {
            	if(csshljczBaList.get(i).getCzid() !=null){
            		CsshljCzForm qsForm = csshljCzService.getForm(csshljczBaList.get(i).getCzid(),  "shlj_cz_v1");
            		csshljczBaFormList.add(convertVoToForm(csshljczBaList.get(i),qsForm));
            	}
            	
            }
            return csshljczBaFormList;
        }
        return null;
    }
    
    public static List<CsshljczBa> convertFormListToVoList(List<CsshljczBaForm> csshljczBaFormList) {
        if(csshljczBaFormList != null && csshljczBaFormList.size() > 0) {
            List<CsshljczBa> csshljczBaList = new ArrayList();
            for(int i=0; i<csshljczBaFormList.size(); i++) {
                CsshljczBa csshljczBa = new CsshljczBa();
                convertFormToVo(csshljczBaFormList.get(i), csshljczBa);
                csshljczBaList.add(csshljczBa);
            }
            return csshljczBaList;
        }
        return null;
    }
}